const fs = require('fs');

fs.readFile('./a.js', 'utf-8', (error, data) => {
    if (error) throw error;
    console.log('读取到的数据:', data);
    
    // 分割成多个键值对
    const info = data.split(',');
    console.log('分割后的数组:', info);
    
    const obj = {};
    for (let i = 0; i < info.length; i++) {
        const keyValue = info[i].split('=='); // 按照 `==` 分割
        if (keyValue.length === 2) { // 确保分割后有两部分
            obj[keyValue[0]] = keyValue[1];
        } else {
            console.log('无效的键值对:', info[i]);
        }
    }
    console.log('生成的对象:', obj);

    // 将对象转换为多行字符串
    let output = '';
    for (const key in obj) {
        if (obj.hasOwnProperty(key)) {
            output += `${key}: ${obj[key]}\n`;
        }
    }

    fs.writeFile('./b.js', output, err => {
        if (err) throw err;
        console.log('写入成功');
    });
});